/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.constant.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 接口操作类型枚举
 *
 * @author hxloongs
 * @date 2024-8-26
 */
@AllArgsConstructor
@Getter
public enum ActionTypeEnum {
    ADD("add", "新增"),
    UPDATE("update", "修改"),
    DOWNLOAD("downLoad", "下载");
    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        ActionTypeEnum actionTypeEnum = forValue(value);
        if (actionTypeEnum == null) {
            return null;
        }
        return actionTypeEnum.getDesc();
    }

    public static ActionTypeEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (ActionTypeEnum actionTypeEnum : ActionTypeEnum.values()) {
            if (actionTypeEnum.getValue().equals(value)) {
                return actionTypeEnum;
            }
        }
        return null;
    }

    public static ActionTypeEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (ActionTypeEnum actionTypeEnum : ActionTypeEnum.values()) {
            if (desc.equals(actionTypeEnum.getDesc())) {
                return actionTypeEnum;
            }
        }
        return null;
    }
}
